import React,{useState} from 'react'

export default function App() {
  const [movies,setMovies] = useState([
    {id:1,name:"《你好，李焕英》",price:50},
    {id:2,name:"《多来A梦，伴我同行》",price:45},
    {id:3,name:"《守岛人》",price:55},
    {id:4,name:"《1921》",price:50},
    {id:5,name:"《中国医生》",price:55},
  ])
  function changePrice (id){
    const index =  movies.findIndex(item=>item.id===id)
    const newMovies = [...movies]
    newMovies[index].price +=1
    setMovies(newMovies)
  }
  return (
    <div>
      <ul>
        {movies.map((item,index)=>{
          return (
            <li key={item.id}>电影名：{item.name}，电影票价{item.price}<button onClick={()=>changePrice(item.id)}>涨价了+1</button></li>
          )
        })}
      </ul>
    </div>
  )
}
